package com.itheima.datastructure;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.function.Consumer;

public class TestSinglyLinkedList {

    @Test
    public void test1(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.loop1(value -> System.out.println(value));
        System.out.println("-------------");
        list.loop2(value-> System.out.println(value));
    }

    @Test
    public void test2(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);

        // 增强for循环底层是调用Iterable的hasNext next方法
        for (Integer value : list) {
            System.out.println(value);
        }
    }

    @Test
    public void test3(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);

        Assertions.assertIterableEquals(List.of(1,2,3,4), list);
        // 增强for循环底层是调用Iterable的hasNext next方法
        for (Integer value : list) {
            System.out.println(value);
        }

        int i = list.get(2);
        System.out.println(i);
    }

    @Test
    public void test4(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);


        list.insert(4, 5);
        list.insert(1, 3);
        for (Integer value : list) {
            System.out.println(value);
        }
    }

    @Test
    public void test5(){
        SinglyLinkedList list = new SinglyLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);

        list.removeFirst();
        for (Integer value : list) {
            System.out.println(value);
        }
    }
}
